package com.wxq.search.controller;
import com.wxq.common.exception.BizCode;
import com.wxq.common.to.SkuEsModel;
import com.wxq.common.utils.R;
import com.wxq.search.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Jim
 * @date 3:10 下午 2022/4/1
 * @description ElasticSearch存储
 * @email:huwmz04153277@126.com
 */

@Slf4j
@RequestMapping("/search/save")
@RestController
public class ElasticSaceController {

    @Autowired
    private ProductService productService;
    @RequestMapping("/product")
    public R productUp(@RequestBody List<SkuEsModel> skuEsModelList){
        boolean flag = false;
        try {
            //返回false，说明商品上架没有异常
            flag = productService.productUp(skuEsModelList);
        }catch (Exception e){
            log.error("ElasticSaveController商品上架错误:{}", e);
            return R.error(BizCode.PRODUCT_UP_EXCEPTION.getCode(), BizCode.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if (!flag){
            return R.ok();
        }else {
            return R.error(BizCode.PRODUCT_UP_EXCEPTION.getCode(), BizCode.PRODUCT_UP_EXCEPTION.getMessage());
        }
    }
}
